import { GATEWAY_URL } from "@/lib/env";
import User from "@/shared/user";

class UserService {
  async getMe(): Promise<User | null> {
    const res = await fetch(`${GATEWAY_URL}/users`, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${localStorage.getItem("token")}`,
      },
    });
    if (res.ok) {
      const json = await res.json();

      return {
        email: json.email,
        name: json.name,
        id: json.id,
        phone: json.phone,
        role: json.role,
      };
    }

    return null;
  }
}

export default new UserService();
